package ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;
import java.util.Vector;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import com.jdbc.EmpVO;
import com.jdbc.JdbcConnectionTest;
class MyDefaultTable extends DefaultTableModel{
	
}
class JTableEventHandler implements ActionListener
{
	static JTableSample jts = null;
	JTableEventHandler(JTableSample jts){
		JTableSample.jts = jts;//this.jts(19) = jts(20)
		//jts.getEmpJTableDisplay();
	}
	@Override
	public void actionPerformed(ActionEvent ae) {
		//search button click check
/*		if(jbtn_search == ae.getSource()){
			List<EmpVO> list = getEmpList();
			JTableSample jts = new JTableSample();
			jts.getEmpJTableDisplay();//method call
		}*/
//		JTableSample jts = new JTableSample();
		JTableSample.jts.getEmpJTableDisplay();//method call
		
	}
	
}
public class JTableSample extends JFrame{
	JButton jbtn_search = new JButton("search");
	MyDefaultTable mft = new MyDefaultTable();
	JTable jtable = new JTable(mft);
	JScrollPane jsp = new JScrollPane(jtable);
	static JTableSample jts = null;
	public JTableSample(){
		//initDisplay();
	}
	public void getEmpJTableDisplay(){
		System.out.println
		("============================");
		System.out.println
		("getEmpJTableDisplay call success!!!");
		JdbcConnectionTest jc = new JdbcConnectionTest();
		EmpVO[] evos = jc.getEmpList3();
		for(int i=0;i<evos.length;i++){
			Vector v = new Vector();
			v.add(evos[i].getEmpno());
			v.add(evos[i].getEname());
			v.add(evos[i].getHiredate());
			mft.addRow(v);
//			EmpVO evo = v.get(i);
//			System.out.println(evo.getEmpno()+":"
//					+evo.getEname()+":"
//					+evo.getHiredate());
		}
	}
	public void initDisplay(){
		mft.addColumn("empno");
		mft.addColumn("ename");
		mft.addColumn("hiredate");
		JTableEventHandler eventHandle = 
				new JTableEventHandler(jts);
		jbtn_search.addActionListener(eventHandle);
		this.add("North",jbtn_search);
		this.add("Center",jsp);
		this.setSize(600, 400);
		this.setVisible(true);
	}
	public static void main(String[] args) {
		jts = new JTableSample();
		jts.initDisplay();
		//new JTableSample();
	}
}
